package com.torry.edss.domain.valueobject;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author torry
 */

@AllArgsConstructor
@Getter
public enum MarketPlate {

    /**
     *
     */
    HSZB(1, Arrays.asList("60", "00"), "沪深主板"),
    KCB_CYB(2, Arrays.asList("68", "3"), "科创板/创业板"),
    HSBG(3, Arrays.asList("90", "20"), "B股"),
    BJS(-1, Arrays.asList("8","92"), "北交所板块"),
    ;

    private Integer code;
    private List<String> prefixes;
    private String decr;


    public static MarketPlate parse(Integer code) {
        return Objects.isNull(code) ? null : Arrays.stream(MarketPlate.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }

    public static MarketPlate getMarketPlate(String companyCode) {
        if (StringUtils.isBlank(companyCode)) return null;
        for (MarketPlate value : MarketPlate.values()) {
            if (value.getPrefixes().stream().anyMatch(companyCode::startsWith)) {
                return value;
            }
        }
        return null;
    }
}
